package Gui;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JTextField;

import Logic.LoginInfo;
import client.LibaryMain;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
/**
 * this class implements the update book details window 
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class UpdateBookDetails extends JPanel{
	private JTextField SearchBooktextField;

	public UpdateBookDetails() {
		
		setBackground(new Color(153, 204, 255));
		setSize(1004,704);
		initConponents();
	
	}
	
	public void initConponents() {
		
		JButton btnBack = new JButton("Back");
		btnBack.setBounds(101, 628, 65, 25);
		btnBack.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnBack.addActionListener(new java.awt.event.ActionListener() {     
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnback(ev);
            					
			}

			private void btnback(ActionEvent ev) {
				MainScreen.cardLayot.show(MainScreen.card,DirectorWindow.roll);
				
			}
        });
		
		JButton btnLogOut = new JButton("Logout");
		btnLogOut.setBounds(791, 628, 83, 25);
		btnLogOut.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnLogOut.addActionListener(new java.awt.event.ActionListener() {      
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnLogOut(ev);
            					
			}

			private void btnLogOut(ActionEvent ev) {
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.add("Logout");
				Arr.add("Worker");
				Arr.add(LoginInfo.UserName);
				LibaryMain.chat.handleMessageFromGui(Arr);
				MainScreen.cardLayot.show(MainScreen.card, "Login");
				
			}
        });
		
		JLabel lblEnterBookId = new JLabel("Enter Book ID");
		lblEnterBookId.setBounds(178, 127, 103, 19);
		lblEnterBookId.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		SearchBooktextField = new JTextField();
		SearchBooktextField.setBounds(320, 125, 329, 23);
		SearchBooktextField.setFont(new Font("Tahoma", Font.BOLD, 14));
		SearchBooktextField.setColumns(10);
		
		JButton btnSearch = new JButton("Search");
		btnSearch.setBounds(698, 124, 79, 25);
		btnSearch.setFont(new Font("Tahoma", Font.BOLD, 14));
		
		btnSearch.addActionListener(new java.awt.event.ActionListener() {      
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnSearch(ev);
            					
			}

			private void btnSearch(ActionEvent ev) {
				
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.clear();
		        Arr.add("UpdateSearch");
		        Arr.add(SearchBooktextField.getText());
				LibaryMain.chat.handleMessageFromGui(Arr);
				
			}
        });
		
		JLabel lblBookInfo = new JLabel("Update Book Information");
		lblBookInfo.setBounds(20, 11, 335, 32);
		lblBookInfo.setForeground(Color.BLACK);
		lblBookInfo.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 26));
		
		JLabel lblTitle = new JLabel("Title : ");
		lblTitle.setBounds(101, 212, 47, 19);
		lblTitle.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		JLabel lblAutor = new JLabel("Autor:");
		lblAutor.setBounds(101, 248, 46, 19);
		lblAutor.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		JLabel lblplaceonshelf = new JLabel("Place On Shelf:");
		lblplaceonshelf.setBounds(101, 301, 114, 19);
		lblplaceonshelf.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		JLabel lblwanted = new JLabel("Wanted:");
		lblwanted.setBounds(101, 333, 62, 19);
		lblwanted.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		JLabel lbleditionnumber = new JLabel("Edition Number:");
		lbleditionnumber.setBounds(101, 379, 120, 19);
		lbleditionnumber.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		JLabel lblprintdate = new JLabel("Print date:");
		lblprintdate.setBounds(101, 427, 79, 19);
		lblprintdate.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		JLabel lblcatalognumber = new JLabel("Catalog Number:");
		lblcatalognumber.setBounds(101, 474, 125, 19);
		lblcatalognumber.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		JLabel lblDescription = new JLabel("Description");
		lblDescription.setBounds(101, 528, 86, 19);
		lblDescription.setFont(new Font("Tahoma", Font.BOLD, 15));

		lblviewautor = new JLabel("aut");
		
		JButton btnEditDescription = new JButton("Edit Description");
		btnEditDescription.setBounds(660, 550, 141, 25);
		btnEditDescription.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditDescription.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				EditDescription(e);
				}

				private void EditDescription(ActionEvent e) {
					
					String EditDescription = JOptionPane.showInputDialog("Please Enter a Description :");
					if(EditDescription==null){}
					else{	
					if(EditDescription.equals(""))
							{
							JOptionPane.showMessageDialog(null, "New Description wasn't entered correctly, please try again");
							}
					else
							{
											ArrayList<String> Arr=new ArrayList<String>();
											Arr.add("EditDescription");
											Arr.add(SearchBooktextField.getText());
											Arr.add(EditDescription);
											LibaryMain.chat.handleMessageFromGui(Arr);
											
							}
					}		
					
					
				}
			});
		
		JButton btnEditCatalogNum = new JButton("Edit Catalog ");
		btnEditCatalogNum.setBounds(660, 482, 141, 25);
		btnEditCatalogNum.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditCatalogNum.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				EditCatalogNum(e);
				}

				private void EditCatalogNum(ActionEvent e) {
					
					String EditCatalogNum = JOptionPane.showInputDialog("Please Enter a catalog num :");
					if(EditCatalogNum==null){}
					else{	
					if(EditCatalogNum.equals(""))
							{
							JOptionPane.showMessageDialog(null, "New catalog num wasn't entered correctly, please try again");
							}
					else
							{
											ArrayList<String> Arr=new ArrayList<String>();
											Arr.add("EditCatalogNum");
											Arr.add(SearchBooktextField.getText());
											Arr.add(EditCatalogNum);
											LibaryMain.chat.handleMessageFromGui(Arr);
											
							}
					}		
					
					
				}
			});
		JButton btnEditPrintDate = new JButton("Edit print date");
		btnEditPrintDate.setBounds(660, 430, 141, 25);
		btnEditPrintDate.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditPrintDate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				EditPrintDate(e);
				}

				private void EditPrintDate(ActionEvent e) {
					
					String EditPrintDate = JOptionPane.showInputDialog("Please Enter a print date :");
					if(EditPrintDate==null){}
					else{	
					if(EditPrintDate.equals(""))
							{
							JOptionPane.showMessageDialog(null, "New print date wasn't entered correctly, please try again");
							}
					else
							{
											ArrayList<String> Arr=new ArrayList<String>();
											Arr.add("EditPrintDate");
											Arr.add(SearchBooktextField.getText());
											Arr.add(EditPrintDate);
											LibaryMain.chat.handleMessageFromGui(Arr);
											
							}
					}		
					
					
				}
			});
		
		JButton btnEditEditionNum = new JButton("Edit Edition ");
		btnEditEditionNum.setBounds(660, 388, 141, 25);
		btnEditEditionNum.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditEditionNum.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				EditionNum(e);
				}

				private void EditionNum(ActionEvent e) {
					
					String EditionNum = JOptionPane.showInputDialog("Please Enter a Edition number :");
					if(EditionNum==null){}
					else{	
					if(EditionNum.equals(""))
							{
							JOptionPane.showMessageDialog(null, "New Edition number wasn't entered correctly, please try again");
							}
					else
							{
											ArrayList<String> Arr=new ArrayList<String>();
											Arr.add("EditionNum");
											Arr.add(SearchBooktextField.getText());
											Arr.add(EditionNum);
											LibaryMain.chat.handleMessageFromGui(Arr);
											
							}
					}		
					
					
				}
			});
		
		JButton btnEditWanted = new JButton("Edit Wanted");
		btnEditWanted.setBounds(660, 342, 141, 25);
		btnEditWanted.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditWanted.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				EditWanted(e);
				}

				private void EditWanted(ActionEvent e) {
					
					String EditWanted = JOptionPane.showInputDialog("Please Enter a Wanted :");
					if(EditWanted==null){}
					else{	
					if(EditWanted.equals(""))
							{
							JOptionPane.showMessageDialog(null, "New Wanted wasn't entered correctly, please try again");
							}
					else
							{
						
						if  ((EditWanted.equals("Yes"))   ||  (EditWanted.equals("No")))
								{
							
							
							ArrayList<String> Arr=new ArrayList<String>();
							Arr.add("EditWanted");
							Arr.add(SearchBooktextField.getText());
					
							Arr.add(EditWanted);
							LibaryMain.chat.handleMessageFromGui(Arr);
							

								}
						else 
						{
							
							JOptionPane.showMessageDialog(null, "Wanted can be equals only to 'Yes' or 'No', please try again");

						}				
							}
					}		
					
					
				}
			});
		
		JButton btnEditPlace = new JButton("Edit Place");
		btnEditPlace.setBounds(660, 304, 141, 25);
		btnEditPlace.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditPlace.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				EditPlace(e);
				}

				private void EditPlace(ActionEvent e) {
					
					String EditPlace = JOptionPane.showInputDialog("Please Enter a Place :");
					if(EditPlace==null){}
					else{	
					if(EditPlace.equals(""))
							{
							JOptionPane.showMessageDialog(null, "New Place wasn't entered correctly, please try again");
							}
					else
							{
											ArrayList<String> Arr=new ArrayList<String>();
											Arr.add("EditPlace");
											Arr.add(SearchBooktextField.getText());
											Arr.add(EditPlace);
											LibaryMain.chat.handleMessageFromGui(Arr);
											
							}
					}		
					
					
				}
			});
		
		JButton btnEditAutor = new JButton("Edit Autor");
		btnEditAutor.setBounds(660, 259, 141, 25);
		btnEditAutor.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditAutor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				editAutor(e);
			}

			private void editAutor(ActionEvent e) {
				
				String editAutor = JOptionPane.showInputDialog("Please Enter a Autor :");
				if(editAutor==null){}
				else{	
				if(editAutor.equals(""))
						{
						JOptionPane.showMessageDialog(null, "New autor wasn't entered correctly, please try again");
						}
				else
						{
										ArrayList<String> Arr=new ArrayList<String>();
										Arr.add("editAutor");
										Arr.add(SearchBooktextField.getText());
										Arr.add(editAutor);
										LibaryMain.chat.handleMessageFromGui(Arr);
										
						}
				}		
				
				
			}
		});
		
				
		
		
		JButton btnEditTitle = new JButton("Edit Title");
		btnEditTitle.setBounds(660, 221, 141, 25);
		btnEditTitle.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnEditTitle.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				editTitle(e);
			}

			private void editTitle(ActionEvent e) {
				// TODO Auto-generated method stub
				
				
				
				String NewTitle = JOptionPane.showInputDialog("Please Enter a Title :");
				if(NewTitle==null){}
				else{	
				if(NewTitle.equals(""))
						{
						JOptionPane.showMessageDialog(null, "New tilte wasn't entered correctly, please try again");
						}
				else
						{
										ArrayList<String> Arr=new ArrayList<String>();
										Arr.add("NewTitle");
										Arr.add(SearchBooktextField.getText());
										Arr.add(NewTitle);
										LibaryMain.chat.handleMessageFromGui(Arr);
										
						}
				}		
				
				
			}
		});
		setLayout(null);
		add(lblBookInfo);
		add(lblEnterBookId);
		add(SearchBooktextField);
		add(btnSearch);
		add(lblTitle);
		add(lblAutor);
		add(lblplaceonshelf);
		add(lblwanted);
		add(lbleditionnumber);
		add(lblprintdate);
		add(lblcatalognumber);
		add(lblDescription);
		add(btnBack);
		add(btnEditTitle);
		add(btnEditPlace);
		add(btnEditWanted);
		add(btnEditEditionNum);
		add(btnEditPrintDate);
		add(btnEditCatalogNum);
		add(btnEditDescription);
		add(btnEditAutor);
		add(btnLogOut);
		
		TitletextField = new JTextField();
		TitletextField.setBounds(241, 211, 390, 32);
		add(TitletextField);
		TitletextField.setColumns(10);
		
		AuthtextField = new JTextField();
		AuthtextField.setBounds(241, 252, 390, 32);
		add(AuthtextField);
		AuthtextField.setColumns(10);
		
		PlacetextField_1 = new JTextField();
		PlacetextField_1.setBounds(241, 295, 390, 32);
		add(PlacetextField_1);
		PlacetextField_1.setColumns(10);
		
		wanttextField_1 = new JTextField();
		wanttextField_1.setBounds(239, 336, 392, 29);
		add(wanttextField_1);
		wanttextField_1.setColumns(10);
		
		editiontextField_1 = new JTextField();
		editiontextField_1.setBounds(239, 378, 392, 35);
		add(editiontextField_1);
		editiontextField_1.setColumns(10);
		
		printtextField_1 = new JTextField();
		printtextField_1.setBounds(239, 426, 392, 35);
		add(printtextField_1);
		printtextField_1.setColumns(10);
		
		catalogtextField_1 = new JTextField();
		catalogtextField_1.setBounds(241, 474, 392, 43);
		add(catalogtextField_1);
		catalogtextField_1.setColumns(10);
		
		descriptiontextField_1 = new JTextField();
		descriptiontextField_1.setBounds(241, 530, 392, 66);
		add(descriptiontextField_1);
		descriptiontextField_1.setColumns(10);
		
		JLabel label = new JLabel("");
		label.setBounds(411, 159, 589, 494);
		label.setIcon(new ImageIcon(UpdateBookDetails.class.getResource("/Gui/images/Xcode_icon.png")));
		add(label);
		
		
		
		
		
	}
/**
 * 
 * @param str with book infomation
 * this function setting the book textfilds 
 */
public void UpdateSearch(String[] str)

{
	this.TitletextField.setText(str[2]); 
	this.AuthtextField.setText(str[3]);  
	this.PlacetextField_1.setText(str[8]); 
	this.wanttextField_1.setText(str[9]); 
	this.editiontextField_1.setText(str[4]); 
	this.printtextField_1.setText(str[5]);  
	this.catalogtextField_1.setText(str[7]);  
	this.descriptiontextField_1.setText(str[6]); 

}
private static JLabel lblviewautor;
private final Action action = new SwingAction();
private final Action action_1 = new SwingAction_1();
private static JTextField TitletextField;
private static JTextField AuthtextField;
private static JTextField PlacetextField_1;
private static JTextField wanttextField_1;
private static JTextField editiontextField_1;
private static JTextField printtextField_1;
private static JTextField catalogtextField_1;
private static JTextField descriptiontextField_1;
	private class SwingAction extends AbstractAction {
		public SwingAction() {
			putValue(NAME, "SwingAction");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}
		public void actionPerformed(ActionEvent e) {
		}
	}
	private class SwingAction_1 extends AbstractAction {
		public SwingAction_1() {
			putValue(NAME, "SwingAction_1");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}
		public void actionPerformed(ActionEvent e) {
		}
	}
}
